<template>
  <div class="top">
    <div class="top_content">
      <div class="top_left" @click="goHome">
        <img src="@/assets/images/logo.png" alt="">
        <p>尚医通 预约挂号统一平台</p>
      </div>
      <div class="top_right">
        <p>帮助中心</p>
<!--        登录前-->
        <p @click="showLogin" v-if="!Login.userInfo.token">登录/注册</p>
<!--        登录后-->
        <el-dropdown v-else>
    <span class="el-dropdown-link">
     {{Login.userInfo.name}}
      <el-icon class="el-icon--right">
        <arrow-down/>
      </el-icon>
    </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="goUser('/user/authentication')">实名认证</el-dropdown-item>
              <el-dropdown-item @click="goUser('/user/orders')">挂号订单</el-dropdown-item>
              <el-dropdown-item @click="goUser('/user/manage')">就诊人管理</el-dropdown-item>
              <el-dropdown-item @click="logOut">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {useRouter} from "vue-router";
import { ArrowDown } from '@element-plus/icons-vue'
import {ElMessage} from "element-plus";

let router = useRouter()

// 引入登录仓库
import {useLogin} from "@/stores/modules/user.ts";

const Login = useLogin()
// 弹出登录页面
const showLogin = () => {
  Login.dialogFormVisible = true
}
const goHome = () => {
  router.push({path: '/home'})
}
// 退出登录
const logOut=()=>{
  Login.userInfo={}
  goHome()
  ElMessage({
    type:'success',
    message:'退出登录成功！'
  })
}

// 路由跳转
const goUser=(where:string)=>{
  router.push({
    path:where
  })
}
</script>


<style scoped lang="scss">
.el-dropdown-link{
  cursor: pointer;
  margin-left: 30px;
}
.top {
  width: 100%;
  height: 70px;
  background-color: #FFFFFF;
  display: flex;
  justify-content: center;
  position: fixed;
  z-index: 999;

  .top_content {
    width: 1200px;
    height: 100%;
    background-color: #FFFFFF;
    display: flex;
    justify-content: space-between;

    .top_left {
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;

      img {
        width: 50px;
        height: 50px;
      }

      p {
        margin-right: 10px;
        font-size: 22px;
        color: #4490F1;
      }
    }

    .top_right {
      display: flex;
      justify-content: center;
      align-items: center;

      p {
        margin-left: 20px;
        cursor: pointer;
        color: #666;
        transition: all .2s ease;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        letter-spacing: 1px;
        display: flex;
        align-items: center;
      }
    }
  }
}
</style>